package com.cirnoworks.uhs.server;

import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Properties;

import com.cirnoworks.uhs.server.impl.UserManagerMockImpl;
import com.google.inject.AbstractModule;
import com.google.inject.name.Names;

public class ServerModule extends AbstractModule {

	@Override
	protected void configure() {
		bind(String.class).annotatedWith(Names.named("hash.method"))
				.toInstance("SHA-256");
		bind(UserManager.class).to(UserManagerMockImpl.class);
		bind(ServerContainer.class).asEagerSingleton();
		Properties properties = new Properties();
		InputStream is = getClass().getResourceAsStream(
				"/uhs-server.properties");
		try {
			properties.load(is);
		} catch (IOException e) {
			throw new RuntimeException(e);
		} finally {
			try {
				is.close();
			} catch (Exception e) {
			}
		}
		Enumeration<?> keys = properties.propertyNames();
		while (keys.hasMoreElements()) {
			String key = (String) keys.nextElement();
			String value = properties.getProperty(key);
			bind(String.class).annotatedWith(Names.named(key))
					.toInstance(value);
		}
	}
}
